home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / lang / amigatalk.lha / intuition / Colors.st < prev    next >
Text File  |  2003-12-02  |  6KB  |  202 lines

  1. "------------------------------------------------------------------"
  2. " Colors Class implements control of Amiga Color registers         "
  3. " Chances are that Glyph is the wrong parent class for this class. "
  4. "------------------------------------------------------------------"
  5.  
  6. Class Colors :Glyph ! private parentObj numberOfColors !
  7. [
  8.    dispose
  9.  
  10.       <primitive 184 0 private>.
  11.       
  12.       <primitive 250 5 0 private>.
  13.       
  14.       ^ nil
  15. |
  16.    loadColors: howMany from: colorMapFileName
  17.  
  18.       <primitive 184 2 parentObj howMany colorMapFileName>
  19. |
  20.    getColor: srcType from: srcObject which: n  
  21.  
  22.       " srcType 1 is WindowObject, all else is colorMapObject: "
  23.  
  24.       ^ <primitive 184 3 srcType srcObject n>
  25. |
  26.    setColorReg: n red: r green: g blue: b
  27.  
  28.       <primitive 184 4 parentObj n r g b>
  29. |
  30.    setMapValue: srcType from: srcObject num: n red: r green: g blue: b
  31.  
  32.       " srcType 1 is WindowObject, all else is colorMapObject: "
  33.  
  34.       <primitive 184 5 srcType srcObject n r g b>
  35. |
  36.    copyMap: sourceObject to: destObject sourceType: srcType
  37.  
  38.       " srcType 1 is WindowObject  (dest is ColorMap)
  39.       * all else is colorMapObject (dest is WindowObject): 
  40.       "
  41.  
  42.       <primitive 184 6 sourceObject destObject srcType>
  43. |
  44.    saveColorsTo: colorMapFileName
  45.  
  46.       <primitive 184 7 parentObj colorMapFileName>
  47.    makeColorMap: numColors
  48.  
  49.       private        <- <primitive 184 1 private numColors>.
  50.  
  51.       numberOfColors <- numColors.
  52.       
  53.       ^ self
  54. |
  55.    new: windowObject
  56.  
  57.       parentObj  <- windowObject.    "cmap <- Colors new: windowObj"
  58.       private    <- nil.             " makeColorMap: will initialize this"
  59.  
  60.       ^ self
  61. ]
  62.  
  63. "------------------------------------------------------------------"
  64. " LargeColors Class implements control of Amiga Color registers    "
  65. " using full 32-bit values for red, green & blue.                  "
  66. " Chances are that Glyph is the wrong parent class for this class. "
  67. "------------------------------------------------------------------"
  68.  
  69. Class LargeColors :Glyph ! private private2 parentObj numberOfColors !
  70. [
  71.    dispose
  72.  
  73.       <primitive 184 0 private>.
  74.       
  75.       <primitive 250 5 0 private>.
  76.  
  77.       (private2 notNil)
  78.          ifTrue: [ <primitive 250 5 0 private2> ].
  79.       
  80.       ^ nil
  81. |
  82.    copyMap: sourceObject to: destObject sourceType: srcType
  83.  
  84.       " srcType 1 is WindowObject  (dest is ColorMap)
  85.       * all else is colorMapObject (dest is WindowObject): 
  86.       "
  87.  
  88.       <primitive 184 6 sourceObject destObject srcType>
  89. |
  90.    saveColorsTo: colorMapFileName
  91.  
  92.       <primitive 184 7 parentObj colorMapFileName>
  93. |
  94.    findColorMatch: red green: green blue: blue
  95.     
  96.       " Find the closest matching color to the RGB values given: "
  97.  
  98.       ^ <primitive 184 8 red green blue private> 
  99. |
  100.    obtainBestPenMatch: red green: green blue: blue tags: tagArray
  101.    
  102.       " Find the closest matching color or allocate one.
  103.       *
  104.       * Valid values for the tagArray are:
  105.       * OBP_Precision - specifies the desired precision for the
  106.       *                 match. Should be PRECISION_GUI, PRECISION_ICON, or
  107.       *                 PRECISION_IMAGE or PRECISION_EXACT.
  108.       *                 Defaults to PRECISION_IMAGE.
  109.       *
  110.       * OBP_FailIfBad - specifies that you want obtainBestPenMatch: to return 
  111.       *                 a failure value if there is not a color within the
  112.       *                 given tolerance, instead of returning the closest color.
  113.       *                 With OBP_FailIfBad==FALSE, obtainBestPen: will only fail
  114.       *                 if the ViewPort contains no sharable colors.
  115.       *                 Defaults to FALSE.
  116.       *
  117.       * NOTE: be sure to use the releasePen: method on the
  118.       * returned value from this method when you are done with it! 
  119.       "
  120.       
  121.       ^ <primitive 184 9 red green blue tagArray private>
  122. |
  123.    obtainPen: red green: green blue: blue flags: flags
  124.    
  125.       " Obtain a free palette entry (if any are left).
  126.       * NOTE: be sure to use the releasePen: method on the
  127.       * returned value from this method when you are done with it! 
  128.       "
  129.       
  130.       ^ <primitive 184 10 red green blue flags private>
  131. |
  132.    releasePen: whichPen
  133.    
  134.       " You MUST use this method for each pen Number returned from
  135.       * obtainBestPenMatch:green:blue:tags: & 
  136.       * obtainPen:green:blue:flags: methods when you are done with
  137.       * them:
  138.       "
  139.       <primitive 184 14 whichPen private> 
  140. |
  141.    getRGB32: firstPen howMany: numColors into: colorArray
  142.    
  143.       " Get a series of color register values & palce them in 
  144.       * colorArray.
  145.       *
  146.       * WARNING:  The size of colorArray MUST be at least 
  147.       * 3 * numColors in length or this method will
  148.       * fail with error messages:
  149.       "
  150.       <primitive 184 11 firstPen numColors colorArray private>
  151. |
  152.    makeColorTable: firstPen howMany: numColors with: colorArray
  153.    
  154.       " Create & format an Array that can be used by the 
  155.       * loadRGB32 method (This is NOT the same as the colorArray 
  156.       * found in the getRGB32:howMany:into: as far as I know!) 
  157.       *
  158.       * The colorArray you supply to this method consists of:
  159.       *
  160.       *    red1 (32-bit), green1 (32-bit), blue1 (32-bit),
  161.       *    ...
  162.       *    redn (32-bit), greenn (32-bit), bluen (32-bit)
  163.       * Triplets
  164.       "
  165.       ^ private2 <- <primitive 184 12 firstPen numColors colorArray>
  166. |
  167.    loadRGB32
  168.    
  169.       " Set a series of color registers for this instance using the
  170.       * colorTable obtained from makeColorTable:howMany:with:
  171.       * method:
  172.       "  
  173.       <primitive 184 13 parentObj private2>
  174. |
  175.    attachExtraPaletteInfo
  176.    
  177.       " Allocate & attach extra palette info to the ColorMap
  178.       * (The dispose method will take care of this): 
  179.       "
  180.       <primitive 184 15 private parentObj>
  181. |
  182.    makeColorMap: numColors
  183.  
  184.       private        <- <primitive 184 1 private numColors>.
  185.  
  186.       numberOfColors <- numColors.
  187.       
  188.       ^ self
  189. |
  190.    new: windowObject
  191.  
  192.       parentObj <- windowObject. "cmap <- Colors new: windowObj"
  193.  
  194.       private   <- nil. " makeColorMap: will initialize this"
  195.       
  196.       private2  <- nil. " makeColorTable:howMany:with: will initialize this"
  197.       
  198.       ^ self
  199. ]
  200.  
  201.